<?
session_start();

include("config.php");

$link = mysql_connect ('localhost', DB_USER_NAME, DB_PASSWORD) or die ("Cannot join database");
mysql_select_db (DB_NAME);




//On affiche un stream particulier
if(isset($_GET['id']))
{
	$requete = "SELECT * FROM stream WHERE id_stream='" . $_GET['id'] . "'";
	$result = mysql_query ($requete);


	if(mysql_num_rows($result) == 0)
	{
		echo "Stream doesn't exist<br>";
	}
	else
	{
		while($row = mysql_fetch_array($result))
		{
			echo $row['resume'] . "<br> <br>";
			echo $row['message'] . "<br>";
	  		//echo "<a href=\"page.html?id=" . $row['id_stream'] . "\">Full news</a>"
		}
		
	}

}
//On liste les streams pour un utilisateur donné
elseif(isset($_GET['user']))
{
	$requete = "SELECT * FROM stream WHERE user='" . $_GET['user'] . "' ORDER BY date DESC";
	$result = mysql_query ($requete);

	if(mysql_num_rows($result) == 0)
	{
		echo "User hasn't posted any stream<br>";
	}
	else
	{
		while($row = mysql_fetch_array($result))
		{
			echo $row['resume'] . " ...<br> <br>";
	  		echo "<a href=\"print_stream.php?id=" . $row['id_stream'] . "\">Full news</a><br><br><br><br>";
		}
		
	}

}
// On affiche la liste des streams auxquels on est abonnés
elseif(isset($_GET['type']))
{
	$requete = "SELECT * FROM stream AS s, abonnement AS a WHERE a.user='" . $_SESSION['pseudo'] . "' AND s.user=a.id_user ORDER BY date DESC LIMIT 0, 10";
	$result = mysql_query ($requete);

	if(mysql_num_rows($result) == 0)
	{
		echo "No stream followed<br>";
	}
	else
	{
		while($row = mysql_fetch_array($result))
		{
			echo $row['resume'] . " ...<br> <br>";
	  		echo "<a href=\"print_stream.php?id=" . $row['id_stream'] . "\">Full news</a><br><br><br><br>";
		}
		
	}

}
else
{
 echo "lol";
}




mysql_close($link);

?>
